package com.jvyou.app.ds.controller;



import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.ds.domain.dto.FaqDto;
import com.jvyou.app.ds.domain.dto.QuestionTypeDto;
import com.jvyou.app.ds.domain.entity.Faq;
import com.jvyou.app.ds.domain.entity.QuestionType;
import com.jvyou.app.ds.service.QuestionTypeService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jvyou.app.common.domain.model.Result;
import com.jvyou.app.common.enums.HttpCodeEnum;

import java.util.List;

/**
 * 题目类型表(QuestionType)表控制层
 *
 * @author 橘柚
 * @since 2025-04-20 19:51:26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/questionType")
public class QuestionTypeController  {
    
    private final QuestionTypeService questionTypeService;


    @GetMapping("/list")
    @SaCheckPermission("ds:questionType:list")
    public Result<List<QuestionType>> list(@ModelAttribute QuestionTypeDto questionTypeDto) {
        return Result.success(questionTypeService.listQuestionType(questionTypeDto));
    }

    @GetMapping("/page")
    @SaCheckPermission("ds:questionType:page")
    public Result<PageResult<QuestionType>> page(@ModelAttribute QuestionTypeDto questionTypeDto) {
        return Result.success(questionTypeService.pageQuestionType(questionTypeDto));
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @SaCheckPermission("ds:questionType:get")
    public Result<QuestionType> selectOne(@PathVariable Long id) {
        return Result.success(questionTypeService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param questionType 实体对象
     * @return 新增结果
     */
    @PostMapping
    @SaCheckPermission("ds:questionType:insert")
    public Result<QuestionType> insert(@RequestBody QuestionType questionType) {
        boolean success = questionTypeService.save(questionType);
        return success ? Result.success(questionType) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
     /**
     * 修改数据
     *
     * @param questionType 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("ds:questionType:update")
    public Result<Boolean> updateById(@RequestBody QuestionType questionType) {
        boolean success = questionTypeService.updateById(questionType);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("ds:questionType:delete")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = questionTypeService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
    
}

